<?php

namespace app\common\dao\info;

use app\common\model\info\AdTask as model;
use app\common\dao\BaseDao;

class AdTaskDao extends BaseDao
{
    /**
    * 设置模型
    * @return model
    */
    protected function getModel(): string
    {
        return model::class;
    }


    public function search($where)
    {
        $query = $this->getModel()::getDB()->alias('ad')->where('ad.status','<>',0)->leftJoin('user u','u.uid = ad.uid');
        $query->when(isset($where['uid']) && $where['uid'] !== '', function ($query)use($where){
            $query->where('ad.uid',$where['uid']);
        })->when(isset($where['title']) && $where['title'] !== '', function ($query)use($where){
            $query->where('ad.title','like',"%{$where['title']}%");
        })->when(isset($where['status']) && $where['status'] !== '', function ($query)use($where){
            if(is_array($where['status'])){
                $query->whereIn('ad.status',$where['status']);
            }else{
                $query->where('ad.status',$where['status']);
            }
        });

        return $query;
    }


}